package com.hulman.oms.web;

import com.hulman.oms.bean.Result;
import com.hulman.oms.bean.PatrolReport;
import com.hulman.oms.bean.ShifterReport;
import com.hulman.oms.bean.User;
import com.hulman.oms.service.PatrolReportService;
import com.hulman.oms.util.DateUtil;
import com.hulman.oms.util.SubjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: maxwellens
 */
@RestController
public class PatrolReportController
{
    @Autowired
    private PatrolReportService patrolReportService;

    @GetMapping("/patrol-reports/{id}")
    public Result findPatrolReportById(@PathVariable Integer id)
    {
        PatrolReport patrolReport = patrolReportService.findPatrolReportById(id);
        return new Result(patrolReport);
    }

    @GetMapping("/patrol-reports")
    public Result findPatrolReports(Integer page, Integer limit, String content, String createByName, Integer state)
    {
        Map<String, Object> map = new HashMap<>();
        map.put("page", page);
        map.put("limit", limit);
        map.put("content", content);
        map.put("createByName", createByName);
        map.put("state", state);
        return patrolReportService.findPatrolReportsResult(map);
    }

    @DeleteMapping("/patrol-reports/{id}")
    public Result deletePatrolReportById(@PathVariable Integer id)
    {
        patrolReportService.deletePatrolReportById(id);
        return Result.SUCCESS;
    }

    @PutMapping("/patrol-reports")
    public Result savePatrolReport(PatrolReport patrolReport)
    {
        patrolReportService.savePatrolReport(patrolReport);
        return Result.SUCCESS;
    }

    @GetMapping("/patrol-reports/create")
    public Result create() throws Exception
    {
        patrolReportService.createPatrolReport(DateUtil.parseDate("2025-05-04"));
        return Result.SUCCESS;
    }

    @PostMapping("/patrol-reports/generate")
    public Result generate(PatrolReport patrolReport) throws IOException
    {
        patrolReportService.generate(patrolReport);
        return Result.SUCCESS;
    }

    @PostMapping("/patrol-reports/submit")
    public Result submitPatrolReport(PatrolReport patrolReport)
    {
        patrolReportService.submitPatrolReport(patrolReport);
        return Result.SUCCESS;
    }

}
